package com.jstyle.beatecg.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import com.google.android.flexbox.AlignItems;
import com.google.android.flexbox.FlexDirection;
import com.google.android.flexbox.FlexWrap;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.google.android.flexbox.JustifyContent;
import com.jstyle.beatecg.R;
import com.jstyle.beatecg.adapter.SportTypeAdapter;
import com.jstyle.beatecg.model.BleData;
import com.jstyle.beatecg.util.GlobalConast;
import com.jstyle.beatecg.util.RxBus;
import butterknife.BindArray;
import butterknife.BindView;
import butterknife.ButterKnife;

public class SportTypeActivity extends AppCompatActivity implements SportTypeAdapter.onItemClickListener {

    @BindView(R.id.recyclerView_sport_type)
    RecyclerView recyclerViewSportType;
    @BindArray(R.array.sport_type_array)
    String[]arraySport;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sport_type);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        FlexboxLayoutManager flexboxLayoutManager=new FlexboxLayoutManager(this);
        flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP);
        flexboxLayoutManager.setFlexDirection(FlexDirection.ROW);
        flexboxLayoutManager.setAlignItems(AlignItems.STRETCH);
        flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START);

        recyclerViewSportType.setLayoutManager(flexboxLayoutManager);
       // recyclerViewSportType.setLayoutManager(linearLayoutManager);
        SportTypeAdapter sportTypeAdapter=new SportTypeAdapter(arraySport,this);
        recyclerViewSportType.setAdapter(sportTypeAdapter);
    }

    @Override
    public void onItemClick(int position) {
        BleData bleData=new BleData();
        bleData.setData(position);
        bleData.setAction(GlobalConast.KEY_SportType);
        RxBus.getInstance().post(bleData);
        finish();
    }
}
